package com.globallogic.primenumbers;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class PrimeNumbers {
    public static void main(String[] args) {
        findPrimeNumbers(getNumber());
    }

    private static int getNumber(){
        int inpNum = -1;
        try {
            BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in));
            System.out.print("Input number: ");
            String cStr = bReader.readLine();
            inpNum = Integer.parseInt(cStr);
        } catch (Exception e) {
                e.printStackTrace();
        }
        return inpNum;
    }

    private static void findPrimeNumbers(int inputNumber) {
        boolean isPrime = true;

        System.out.print("Prime numbers: ");
        for (int number = inputNumber; number > 1; number--) {
            isPrime = true;
            int i = number;

            do {
                i--;
                if ((number % i == 0) && (i > 1)) {
                    isPrime = false;
                }
            }
            while ((i > 2) && isPrime);

            if (isPrime) {
                System.out.print(number + " ");
            }
        }
    }
}